import ccclass = cc._decorator.ccclass;
import property = cc._decorator.property;
import {TipsType} from "../utils/wordsUtils";

@ccclass()
export class WordTips extends cc.Component {
  @property(cc.Label)
  private txt: cc.Label = null
  @property(cc.Sprite)
  private bgSprite: cc.Sprite = null
  @property(cc.SpriteFrame)
  private successSpriteFrame: cc.SpriteFrame = null
  @property(cc.SpriteFrame)
  private errorSpriteFrame: cc.SpriteFrame = null
  @property(cc.SpriteFrame)
  private warnSpriteFrame: cc.SpriteFrame = null
  @property(cc.SpriteFrame)
  private messageSpriteFrame: cc.SpriteFrame = null

  showText(text: string, type: TipsType) {
    this.txt.string = text
    switch (type) {
      case TipsType.ERROR:
        this.bgSprite.spriteFrame = this.errorSpriteFrame
        this.txt.node.color = new cc.Color().fromHEX('#e5463f')
        break
      case TipsType.MESSAGE:
        this.bgSprite.spriteFrame = this.messageSpriteFrame
        this.txt.node.color = new cc.Color().fromHEX('#45eaee')
        break
      case TipsType.SUCCESS:
        this.bgSprite.spriteFrame = this.successSpriteFrame
        this.txt.node.color = new cc.Color().fromHEX('#a2f36f')
        break
      case TipsType.WARN:
        this.bgSprite.spriteFrame = this.warnSpriteFrame
        this.txt.node.color = new cc.Color().fromHEX('#fff79a')
        break
    }
  }
}